package com.spring.service.blog.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.spring.web.formbean.blog.BlogCommentForm;
import com.spring.bean.blog.BlogComment;
import com.spring.dao.blog.BlogCommentDao;
import com.spring.service.blog.BlogCommentService;
import com.spring.bean.page.Page;
import com.spring.bean.page.PageView;
import com.spring.service.ServiceSupport;
import com.spring.exception.ServiceException;

@Service
@Transactional
public class BlogCommentServiceImpl extends ServiceSupport implements BlogCommentService {

	@Autowired
	private BlogCommentDao blogCommentDao;

	/** insert */
	public boolean insert(BlogCommentForm blogCommentForm) throws ServiceException {
		try{
			BlogComment blogComment = formToEntity(BlogComment.class, blogCommentForm);
			return blogCommentDao.insert(blogComment);
		} catch (Exception e) {
			throw new ServiceException("BlogComment --- insert error", e);
		}
	}

	/** update */
	public boolean update(BlogCommentForm blogCommentForm) throws ServiceException {
		try{
			BlogComment blogComment = formToEntity(BlogComment.class, blogCommentForm);
			return blogCommentDao.update(blogComment);
		} catch (Exception e) {
			throw new ServiceException("BlogComment --- update error", e);
		}
	}

	/** delete */
	public boolean delete(Integer id) throws ServiceException {
		try{
			return blogCommentDao.delete(id);
		} catch (Exception e) {
			throw new ServiceException("BlogComment --- delete error", e);
		}
	}

	/** getById */
	public BlogComment getById(Integer id) throws ServiceException {
		try{
			return blogCommentDao.getById(id);
		} catch (Exception e) {
			throw new ServiceException("BlogComment --- query by id error", e);
		}
	}

	/** queryForList */
	public List<BlogComment> queryForList() throws ServiceException {
		try{
			return blogCommentDao.queryForList();
		} catch (Exception e) {
			throw new ServiceException("BlogComment --- query list error", e);
		}
	}

	/** queryForPage */
	public PageView<BlogComment> queryForPage(Page page) throws ServiceException {
		try{
			return blogCommentDao.queryForPage(page);
		} catch (Exception e) {
			throw new ServiceException("BlogComment ---query page error", e);
		}
	}
}